Skip to content

Fix case sensitive environment variable lookup#1001

Merged
pragya811 merged 1 commit into
mainfrom
jenkins_fix2
Jun 10, 2026
Merged

Fix case sensitive environment variable lookup#1001
pragya811 merged 1 commit into
mainfrom
jenkins_fix2

Conversation

@pragya811

Copy link
Copy Markdown
Member

Type of change

Note: Fill x in []

  • bug
  • enhancement
  • documentation
  • dependencies

Description

The get_env() method was case-sensitive when looking up environment variables. Jenkins sets:
ES_HOST (uppercase)
ES_PORT (uppercase)

But the code was looking for:
es_host (lowercase)
es_port (lowercase)

On Linux/Unix systems, os.environ is case-sensitive, so os.environ.get('es_port') won't find ES_PORT, returning an empty string ''. Then when the code tried to do int('') on line 53 or 63 of elasticsearch_operations.py, it failed with invalid literal for int() with base 10: ''.

Fix

Updated the get_env() method in environment_variables.py to check for the variable in multiple case variations

For security reasons, all pull requests need to be approved first before running any automated CI

Assisted-by: Cursor

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved environment variable resolution to handle case variations more flexibly, reducing configuration errors from case-sensitivity mismatches.

Walkthrough

The PR modifies the get_env method in EnvironmentVariables to resolve environment variable values case-insensitively. The method now checks the provided key, its uppercase variant, and its lowercase variant in sequence, falling back to the default value, and uses the computed value consistently for argparse setup and return behavior.

Changes

Case-insensitive environment variable resolution

Layer / File(s) Summary
get_env case-insensitive lookup
cloud_governance/main/environment_variables.py
The get_env method computes a single env_value by trying the key in its original form, then uppercase, then lowercase, with defval as fallback. This computed value is used for all argparse defaults and returned consistently, eliminating duplicate os.environ lookups.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing case-sensitive environment variable lookup, which is the core purpose of this PR.
Description check ✅ Passed The description clearly explains the problem (case-sensitive lookup causing failures), the context (Jenkins uses uppercase variables), and the solution (check multiple case variations).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cloud_governance/main/environment_variables.py`:
- Line 395: The line assigning env_value currently treats empty strings as falsy
and can skip an explicitly set empty env var; update the lookup in the scope
where env_value is assigned (the expression using os.environ.get(var) /
var.upper() / var.lower() in environment_variables.py) to perform explicit
existence checks (e.g., check "if var in os.environ" then use os.environ[var],
else check var.upper(), var.lower(), else use defval) so that an explicitly set
empty string is preserved while still providing case-insensitive fallbacks and
finally the default.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: fcc46fe7-4cf4-44aa-8760-253003f9ed53

📥 Commits

Reviewing files that changed from the base of the PR and between fbbe8cd and 6497df2.

📒 Files selected for processing (1)
  • cloud_governance/main/environment_variables.py

def get_env(var: str, defval=''):
lcvar = var.lower()
dashvar = lcvar.replace('_', '-')
env_value = os.environ.get(var) or os.environ.get(var.upper()) or os.environ.get(var.lower()) or defval

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Empty string handling bug in case-insensitive lookup.

The or chaining treats empty strings as falsy, which means an explicitly set environment variable like ES_PORT='' would be skipped in favor of checking other case variations or the default value. While unlikely in practice, this could cause confusing behavior where an explicitly set value is ignored.

🔧 Proposed fix using explicit existence checks
-        env_value = os.environ.get(var) or os.environ.get(var.upper()) or os.environ.get(var.lower()) or defval
+        for key in (var, var.upper(), var.lower()):
+            if key in os.environ:
+                env_value = os.environ[key]
+                break
+        else:
+            env_value = defval

This approach respects explicitly set empty strings while still providing the case-insensitive fallback behavior.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
env_value = os.environ.get(var) or os.environ.get(var.upper()) or os.environ.get(var.lower()) or defval
for key in (var, var.upper(), var.lower()):
if key in os.environ:
env_value = os.environ[key]
break
else:
env_value = defval
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cloud_governance/main/environment_variables.py` at line 395, The line
assigning env_value currently treats empty strings as falsy and can skip an
explicitly set empty env var; update the lookup in the scope where env_value is
assigned (the expression using os.environ.get(var) / var.upper() / var.lower()
in environment_variables.py) to perform explicit existence checks (e.g., check
"if var in os.environ" then use os.environ[var], else check var.upper(),
var.lower(), else use defval) so that an explicitly set empty string is
preserved while still providing case-insensitive fallbacks and finally the
default.

@ebattat ebattat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@pragya811 pragya811 merged commit 9be8c00 into main Jun 10, 2026
24 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Cloud-Governance project Jun 10, 2026
@pragya811 pragya811 deleted the jenkins_fix2 branch June 10, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants